package com.emeraldparser.util;

import java.util.Collection;
import java.util.Set;

import com.google.common.collect.HashBasedTable;
import com.google.common.collect.Sets;

public final class HashBasedMultitable<R, C, V> extends AbstractSetMultitable<R, C, V> {

	private static final int DEFAULT_VALUES_PER_KEY = 8;

	transient int expectedValuesPerKey = DEFAULT_VALUES_PER_KEY;

	public static <R, C, V> HashBasedMultitable<R, C, V> create() {
		return new HashBasedMultitable<R, C, V>(HashBasedTable.<R, C, Collection<V>>create());
	}

	public static <R, C, V> HashBasedMultitable<R, C, V> create(int expectedRows, int expectedCellsPerRow) {
		return new HashBasedMultitable<R, C, V>(HashBasedTable.<R, C, Collection<V>>create(expectedRows, expectedCellsPerRow));
	}

	public static <R, C, V> HashBasedMultitable<R, C, V> create(Multitable<? extends R, ? extends C, ? extends V> multitable) {
		HashBasedMultitable<R, C, V> result = create();
		result.putAll(multitable);
		return result;
	}

	private HashBasedMultitable(HashBasedTable<R, C, Collection<V>> table) {
		super(table);
	}

	@Override
	Set<V> createCollection() {
		return Sets.newHashSet();
	}

}
